using System;
using System.Windows.Forms;

namespace Inikus.WinTimer
{
    public partial class frmReports : Form
    {
        public frmReports(dsWinTimer ds)
        {
            InitializeComponent();
            dsWinTimer = ds;
        }

        private void frmReports_Load(object sender, EventArgs e)
        {
            dsWinTimerBindingSource.DataSource = dsWinTimer;
            dsWinTimerBindingSource.Sort = "StartTime DESC";
            dateStart.Value = DateTime.Today;
            dateEnd.Value = DateTime.Today;
            dateStart_ValueChanged(sender, e);
        }

        private void dateStart_ValueChanged(object sender, EventArgs e)
        {
            dsWinTimerBindingSource.Filter = "StartTime >= '" + dateStart.Value.ToShortDateString() +
                "' AND StartTime <= '" + dateEnd.Value.ToShortDateString() + " 23:59:59'";
            SetTotalTime();
        }

        private void SetTotalTime()
        {
            int duration = 0;
            foreach (DataGridViewRow row in gridReport.Rows)
            {
                duration += Convert.ToInt32(row.Cells["colDuration"].Value);
            }

            TimeSpan ts = new TimeSpan(0, 0, duration);
            lblTotalHours.Text = ts.TotalHours.ToString("0.0");
        }
    }
}